package com.jiutian.cmsskitdev.controller;

import com.jiutian.cmsskitdev.Main;
import com.jiutian.cmsskitdev.config.ControllerStage;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.layout.AnchorPane;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class HomeController implements ControllerStage, Initializable {

    StageController stageController;
    @FXML
    private AnchorPane contentPanes;

    @FXML
    void addDevice(ActionEvent event) throws IOException {
        //AnchorPane pane = FXMLLoader.load(getClass().getResource("/com/jiutian/cmsskitdev/DeviceManage.fxml"));
//        contentPane.getChildren().clear();
//        contentPane.getChildren().setAll(other);


//        contentPane.getChildren().clear();
//        contentPane.getChildren().add(pane);

//        Parent homeRoot = FXMLLoader.load(getClass().getResource("/com/jiutian/cmsskitdev/DeviceManage.fxml"));
//        Scene homeScene = new Scene(homeRoot);
//        Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
//        stage.setScene(homeScene);

    }

    @FXML
    void checkHeath(ActionEvent event) {

    }

    @FXML
    void clusterDeployment(ActionEvent event) {

    }

    @FXML
    void deviceMange(ActionEvent event) throws IOException {
          stageController.setStage(Main.mainViewRes, contentPanes);
//        ObservableList<Node> scrolChildren = contentPanes.getChildren();
//        scrolChildren.clear();
//        scrolChildren.add(FXMLLoader.load(getClass().getResource("/com/jiutian/cmsskitdev/DeviceManage.fxml")));

    }

    @FXML
    void init(ActionEvent event) throws IOException {
        ObservableList<Node> scrolChildren = contentPanes.getChildren();
        scrolChildren.clear();
        scrolChildren.add(FXMLLoader.load(getClass().getResource("/com/jiutian/cmsskitdev/mainSubPage.fxml")));

    }

    @FXML
    void tools(ActionEvent event) {

    }

    @Override
    public void setStageController(StageController stagecontroller) {
        this.stageController = stagecontroller;
    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {

    }

    public void goToMain(){
//        System.out.println(Main.mainViewID);
//        myController.setStage(Main.mainViewID);
    }
}
